#!/usr/bin/env ruby
#
# Copyright 2009 Jeffrey Palm
#


require 'server'
require 'config'

# These guys will simply print out the request.  They will finish
# their work after 3 times.  i.e. 'handle' will return 'true' for the
# first 3 times and then start to return 'false' after to tell the
# server she's done.
class EchoHandler < Server::Handler

  def initialize
    super 'George', /.*/
    @count = 0
  end

  def handle(request)
    puts 'request : ' + request
    puts 'count   : ' + @count.to_s
    @count += 1
    return @count > 3
  end

end

#
# Starts up a simple Server and waits for connections.  The arguments
# are defined in config.rb.
#
def main(args)
  c = Config.get_instance args
  s = Server.new EchoHandler.new
  s.start c.addr,c.port
end


main ARGV
